home *** CD-ROM | disk | FTP | other *** search
- Path: news.sprintlink.net!datalytics!usenet
- From: Rob Stewart <stew@datalytics.com>
- Newsgroups: comp.lang.c++
- Subject: Re: ? Accessing members of classes within classes
- Date: Thu, 18 Apr 1996 09:33:01 -0400
- Organization: Datalytics, Inc
- Message-ID: <3176448D.13D2@datalytics.com>
- References: <4l3k7a$rjo@hammer.msfc.nasa.gov>
- NNTP-Posting-Host: 204.62.224.71
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (WinNT; I)
-
- NS130355@ wrote:
- >
- > What is the proper method of accessing the public members
- > of a class used in a "has a" relationship within another
- > class as a public member?
-
- Make them private and provide accessor/modifier functions!
-
- >
- > Example:
- >
- > class firstClass
- > {
- > private: char mydata[10];
- >
- > public: int setMydata(char *);
- > char* getMydata(void);
- > }
-
- ------^
- missing semicolon
-
- >
- > class secondClass
- > {
- > private: char mydata2[10];
- >
- > public: firstClass cMember[10];
- > int setMydata2(char *);
- > char* getMydata2(void);
- > }
-
- ------^
- missing semicolon
-
- >
- > int main
-
- ----------^
- missing parameter list (even "(void)")
-
- > {
- > // THIS DOESN'T COMPILE. WHY?
- > secondClass myObject;
- > myObject.cMember[0].setMydata("HELLO");
-
- I don't see anything wrong with this and it compiles on VC 4.1.
- Neither is conclusive, but I think your compiler is at fault.
-
- [snip]
-
- --
- Robert Stewart | My opinions are usually my own.
- Datalytics, Inc. | stew@datalytics.com
-